package edu.kit.ksri.db.mturk.plugins.performance;

import java.util.Date;

/**
 * Copyright (c) 2010-2011 Karlsruhe Institute of Technology (KIT), Germany
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 * 
 * --------------------------------------------------------------------------
 * 
 * Software: CSP/WMV tool for dynamic quality management of microtasks
 * http://www.ksri.kit.edu/Upload/Users/PeopleClouds/HCOMP2011_An_extendable_toolkit_for_managing_quality_of_human-based_eServices.pdf
 * 
 * Organization: Karlsruhe Institute of Technology (KIT), Germany
 * http://www.kit.edu
 * 
 * Project: PeopleClouds project of the Karlsruhe Service Research Institute(KSRI)
 * http://www.ksri.kit.edu/Default.aspx?PageId=818
 * 
 * Contributing authors: David Bermbach, Sandra Rath, Pascal Wichmann, Robert Kern
 * 
 * ---------------------------------------------------------------------------
 * 
 * Purpose: This class serves as a wrapping data structure for data collected during a
 * snapshot by the {@link TimeConstraintsManager}.
 */
public class ProgressSnapshot {

	/**
	 * The number of assignments which have been completed per minute since the
	 * last snapshot on average
	 */
	private double assignmentsCompletedPerMinute = 0;

	/** The total number of assignments that has been completed so far */
	private int numberOfAssignmentsCompleted = 0;

	/** how many people are currently allowed to work in total */
	private int activePoolSize = 0;

	/**
	 * how many workers have actually submitted an assignment during the last
	 * snapshot period
	 */
	private int numberOfDistinctWorkers = 0;

	/** the date of the snapshot */
	private Date snapshotDate;

	/**
	 * @param assignmentsCompletedPerMinute
	 * @param numberOfAssignmentsCompleted
	 * @param activePoolSize
	 * @param numberOfDistinctWorkers
	 * @param snapshotDate
	 */
	public ProgressSnapshot(double assignmentsCompletedPerMinute,
			int numberOfAssignmentsCompleted, int activePoolSize,
			int numberOfDistinctWorkers, Date snapshotDate) {
		super();
		this.assignmentsCompletedPerMinute = assignmentsCompletedPerMinute;
		this.numberOfAssignmentsCompleted = numberOfAssignmentsCompleted;
		this.activePoolSize = activePoolSize;
		this.numberOfDistinctWorkers = numberOfDistinctWorkers;
		this.snapshotDate = snapshotDate;
	}

	/**
	 * 
	 */
	public ProgressSnapshot() {
		super();
	}

	/**
	 * 
	 * @return the headers for CSV export
	 */
	public static String getCSVHeaders() {
		String prefix = "\"", suffix = "\";";
		String res = "";
		res += prefix + "Date" + suffix;
		res += prefix + "Total Assignments Completed" + suffix;
		res += prefix + "Assignments / min" + suffix;
		res += prefix + "Active Pool Size" + suffix;
		return res;
	}

	public String getCSVString() {
		String prefix = "\"", suffix = "\";";
		String res = "";
		res += prefix + snapshotDate + suffix;
		res += prefix + numberOfAssignmentsCompleted + suffix;
		res += prefix + assignmentsCompletedPerMinute + suffix;
		res += prefix + activePoolSize + suffix;

		return res;
	}

	/**
	 * @return the assignmentsCompletedPerMinute
	 */
	public double getAssignmentsCompletedPerMinute() {
		return this.assignmentsCompletedPerMinute;
	}

	/**
	 * @param assignmentsCompletedPerMinute
	 *            the assignmentsCompletedPerMinute to set
	 */
	public void setAssignmentsCompletedPerMinute(
			double assignmentsCompletedPerMinute) {
		this.assignmentsCompletedPerMinute = assignmentsCompletedPerMinute;
	}

	/**
	 * @return the numberOfAssignmentsCompleted
	 */
	public int getNumberOfAssignmentsCompleted() {
		return this.numberOfAssignmentsCompleted;
	}

	/**
	 * @param numberOfAssignmentsCompleted
	 *            the numberOfAssignmentsCompleted to set
	 */
	public void setNumberOfAssignmentsCompleted(int numberOfAssignmentsCompleted) {
		this.numberOfAssignmentsCompleted = numberOfAssignmentsCompleted;
	}

	/**
	 * @return the activePoolSize
	 */
	public int getActivePoolSize() {
		return this.activePoolSize;
	}

	/**
	 * @param activePoolSize
	 *            the activePoolSize to set
	 */
	public void setActivePoolSize(int activePoolSize) {
		this.activePoolSize = activePoolSize;
	}

	/**
	 * @return the numberOfDistinctWorkers
	 */
	public int getNumberOfDistinctWorkers() {
		return this.numberOfDistinctWorkers;
	}

	/**
	 * @param numberOfDistinctWorkers
	 *            the numberOfDistinctWorkers to set
	 */
	public void setNumberOfDistinctWorkers(int numberOfDistinctWorkers) {
		this.numberOfDistinctWorkers = numberOfDistinctWorkers;
	}

	/**
	 * @return the snapshotDate
	 */
	public Date getSnapshotDate() {
		return this.snapshotDate;
	}

	/**
	 * @param snapshotDate
	 *            the snapshotDate to set
	 */
	public void setSnapshotDate(Date snapshotDate) {
		this.snapshotDate = snapshotDate;
	}

}
